#!/usr/bin/env python
# encoding: utf-8
"""
@author:zwb
@file: base_manager.py
@contact: zwb15083976291@163.com
@time: 2021/11/10
"""
from django.db.models.manager import BaseManager
from django.db.models.query import QuerySet
from django.core.paginator import Paginator


class CustomQuerySet(QuerySet):

    def first(self):
        """
        获取第一条记录，避免first()方法排序
        :return:
        """
        for obj in self[:1]:
            return obj


    def paginate(self, per_page: 'limit page show') -> Paginator:
        """
        返回一个分页器对象
        :param per_page: 每页的数量
        :return:
        """
        return Paginator(self, per_page)


class BaseDBManager(BaseManager.from_queryset(CustomQuerySet)):
    """模型管理基类"""
    pass
